Skip to content

ENT-13880: Added error-checks for half-promises / attrs without promiser outside of macros#86

Merged
olehermanse merged 2 commits intocfengine:mainfrom
SimonThalvorsen:ENT-13880
Apr 29, 2026
Merged

ENT-13880: Added error-checks for half-promises / attrs without promiser outside of macros#86
olehermanse merged 2 commits intocfengine:mainfrom
SimonThalvorsen:ENT-13880

Conversation

@SimonThalvorsen
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/cfengine_cli/lint.py Outdated
Comment thread tests/lint/016_half_promises.cf Outdated
Copy link
Copy Markdown
Member

@olehermanse olehermanse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See commments above.

Comment thread tests/lint/016_half_promises.cf Outdated
@SimonThalvorsen SimonThalvorsen force-pushed the ENT-13880 branch 2 times, most recently from 2926000 to a575aa3 Compare April 29, 2026 12:15
Comment thread src/cfengine_cli/lint.py
self.old_state = deepcopy(self.__dict__)
self.macro = macro_type.split(" ")[-1]
elif macro_type.startswith("@else"):
self.macro = "else"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future it might be valuable to know what macro we are in the @else of. (Essentially, !minimum_version(3.24) for example).

Comment thread src/cfengine_cli/lint.py
Comment on lines +779 to +794
prev_sib = node.prev_named_sibling
while prev_sib and prev_sib.type == "comment":
prev_sib = prev_sib.prev_named_sibling
prev_type = prev_sib.type if prev_sib else None
if not state.macro:
_highlight_range(node, lines)
print(
f"Error: Found promise attribute with no parent-promiser outside of a macro {location}"
)
return 1
elif prev_type != "macro":
_highlight_range(node, lines)
print(
f"Error: Multiple promise attributes with ending semicolon found inside macro '{state.macro}' {location}"
)
return 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else when you do early return. No need to look through previous nodes when you are not going to use the result;

Suggested change
prev_sib = node.prev_named_sibling
while prev_sib and prev_sib.type == "comment":
prev_sib = prev_sib.prev_named_sibling
prev_type = prev_sib.type if prev_sib else None
if not state.macro:
_highlight_range(node, lines)
print(
f"Error: Found promise attribute with no parent-promiser outside of a macro {location}"
)
return 1
elif prev_type != "macro":
_highlight_range(node, lines)
print(
f"Error: Multiple promise attributes with ending semicolon found inside macro '{state.macro}' {location}"
)
return 1
if not state.macro:
_highlight_range(node, lines)
print(
f"Error: Found promise attribute with no parent-promiser outside of a macro {location}"
)
return 1
prev_sib = node.prev_named_sibling
while prev_sib and prev_sib.type == "comment":
prev_sib = prev_sib.prev_named_sibling
prev_type = prev_sib.type if prev_sib else None
if prev_type != "macro":
_highlight_range(node, lines)
print(
f"Error: Multiple promise attributes with ending semicolon found inside macro '{state.macro}' {location}"
)
return 1

@olehermanse olehermanse merged commit 46b9a07 into cfengine:main Apr 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants